<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class League extends CI_Controller {

	function __construct()
	{
		parent::__construct();
	}

    function index()
    {
        $data['title'] = "New Jersey Devils - League";
        $data['body'] = "v_league";
	$data['groups'] = "undefined";
        $this->load->vars($data);
        $this->load->view('template');
    }
    
    function process()
    {
        $orderBy = $this->input->post('orderBy');
        $league = simplexml_load_file("./data/comp4711-nhl-teams.xml");
        $groups = array();
	
	if($orderBy == null || $orderBy == "league"){
		foreach ($league->group as $group){
			$groups[] = $group;
		}
	} else if ($orderBy == "div"){
		foreach ($league->group as $group){
			if($group->team['div'] == "Pacific"){
				$groups[] = $group;
			}
		}
		foreach ($league->group as $group){
			if($group->team['div'] == "Northwest"){
				$groups[] = $group;
			}
		}
		foreach ($league->group as $group){
			if($group->team['div'] == "Central"){
				$groups[] = $group;
			}
		}
		foreach ($league->group as $group){
			if($group->team['div'] == "Southeast"){
				$groups[] = $group;
			}
		}
		foreach ($league->group as $group){
			if($group->team['div'] == "Northeast"){
				$groups[] = $group;
			}
		}
		foreach ($league->group as $group){
			if($group->team['div'] == "Atlantic"){
				$groups[] = $group;
			}
		}
	} else if($orderBy == "con"){
		foreach ($league->group as $group){
			if($group->team['conf'] == "Western"){
				$groups[] = $group;
			}
		}
		foreach ($league->group as $group){
			if($group->team['conf'] == "Eastern"){
				$groups[] = $group;
			}
		}
	}


        $data['title'] = "League";
	//if($orderBy == null || $orderBy == "league"){
	//	$data['body'] = "v_leaguenone";
	//} else if($orderBy == "div"){
	//	$data['body'] = "v_leaguediv";
	//} else if($orderBy == "con"){
	//	$data['body'] = "v_leaguecon";
	//} else {
		$data['body'] = "v_league";
	//}
        $data['groups'] = $groups;
        $this->load->vars($data);
        $this->load->view('template');
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */